{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "2f9605aa",
   "metadata": {},
   "source": [
    "-----------\n",
    "* 2022/09/06/week03\n",
    "* python 课堂笔记\n",
    "----------------\n"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "c831c668",
   "metadata": {},
   "source": [
    "# 本周知识点\n",
    "\n",
    "## 1.回顾变量的概念"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "b96890f0",
   "metadata": {},
   "outputs": [],
   "source": [
    "网新_01_ID = \"21000001\"  # \n",
    "\n",
    "网新_01_ID = \"21000002\""
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "id": "8bba8c76",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'21000002'"
      ]
     },
     "execution_count": 3,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "网新_01_ID"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "id": "1d72dd3f",
   "metadata": {},
   "outputs": [],
   "source": [
    "网新_01_Age = \"18\""
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "id": "efcb41f0",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'18'"
      ]
     },
     "execution_count": 5,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "网新_01_Age"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "f8cdcac2",
   "metadata": {},
   "source": [
    "## 2.条件判断\n",
    "> 1.if else"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "id": "0823c836",
   "metadata": {},
   "outputs": [],
   "source": [
    "## 3.关于模块，变量和if条件变量 "
   ]
  },
  {
   "cell_type": "markdown",
   "id": "5c187e31",
   "metadata": {},
   "source": [
    "* 判断当前是一周的星期几，，如果是星期二，看下现在几点了，是python课ing吗？然后打印Python课表\n",
    "* 实践，通过if判断 实现课程表打印\n",
    "* 课本P18"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "id": "7024e673",
   "metadata": {},
   "outputs": [
    {
     "ename": "NameError",
     "evalue": "name 'datetime' is not defined",
     "output_type": "error",
     "traceback": [
      "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m",
      "\u001b[1;31mNameError\u001b[0m                                 Traceback (most recent call last)",
      "Input \u001b[1;32mIn [8]\u001b[0m, in \u001b[0;36m<cell line: 1>\u001b[1;34m()\u001b[0m\n\u001b[1;32m----> 1\u001b[0m help(\u001b[43mdatetime\u001b[49m)\n",
      "\u001b[1;31mNameError\u001b[0m: name 'datetime' is not defined"
     ]
    }
   ],
   "source": [
    "help(datetime)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "abd25baa",
   "metadata": {},
   "outputs": [],
   "source": [
    "import datetime\n",
    "datetime.datetime.today()\n",
    "# datetime可以获取到年月日，不能获取到周几"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "id": "e271e780",
   "metadata": {},
   "outputs": [
    {
     "ename": "NameError",
     "evalue": "name 'datetime' is not defined",
     "output_type": "error",
     "traceback": [
      "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m",
      "\u001b[1;31mNameError\u001b[0m                                 Traceback (most recent call last)",
      "Input \u001b[1;32mIn [9]\u001b[0m, in \u001b[0;36m<cell line: 1>\u001b[1;34m()\u001b[0m\n\u001b[1;32m----> 1\u001b[0m \u001b[43mdatetime\u001b[49m\u001b[38;5;241m.\u001b[39mdate(\u001b[38;5;241m2022\u001b[39m,\u001b[38;5;241m9\u001b[39m,\u001b[38;5;241m6\u001b[39m)\n",
      "\u001b[1;31mNameError\u001b[0m: name 'datetime' is not defined"
     ]
    }
   ],
   "source": [
    "datetime.date(2022,9,6)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "803e1d8e",
   "metadata": {},
   "outputs": [],
   "source": [
    "# 创建today变量（用模块获取到今天星期几）\n",
    "# 知识点：1.先创建变量，才能进行判断\n",
    "      \n",
    "today = \"Sunday\"\n",
    "condition = \"Headache\"\n",
    "\n",
    "if today == \"Saturday\":\n",
    "     print(\"放假啦！\") # ==是判断的意思 if条件判断块\n",
    "elif today == \"Sunday\":\n",
    "    if condition == \"Headache\":\n",
    "        print(\"Recover, then rest.\")\n",
    "    else:\n",
    "        print()\n",
    "   \n",
    " "
   ]
  },
  {
   "cell_type": "markdown",
   "id": "7fcbc7d9",
   "metadata": {},
   "source": [
    "* 判断当前是一周的星期几，，如果是星期二，看下现在几点了，是python课ing吗？然后打印Python课表"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 31,
   "id": "f9d20e78",
   "metadata": {},
   "outputs": [],
   "source": [
    "# weekday = 0,1,2,3,4,5,6  分别指周一到周日\n",
    "import time\n",
    "\n",
    "wday  = time.localtime().tm_wday"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 32,
   "id": "dbeda03e",
   "metadata": {},
   "outputs": [],
   "source": [
    "time_hour= time.localtime().tm_hour"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 33,
   "id": "f1b31327",
   "metadata": {},
   "outputs": [],
   "source": [
    "time_min  = time.localtime().tm_min"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 34,
   "id": "a4392805",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "还在上python课，快疯了\n"
     ]
    }
   ],
   "source": [
    "if wday != 1: # 判断是否是周二\n",
    "    print(\"今天没有Python课\")\n",
    "elif time_hour == 12 and time_min > 50:\n",
    "        print(\"现在在上python课\")\n",
    "elif time_hour ==13:\n",
    "        print(\"正在上python课，大概第二节了\")\n",
    "elif time_hour ==14:\n",
    "        print(\"还在上python课，快疯了\")\n",
    "elif time_hour ==15:\n",
    "        print(\"好饿啊，倒二节课\")\n",
    "else:\n",
    "    print(\"今天有python课，一个下午\")\n",
    "    "
   ]
  },
  {
   "cell_type": "markdown",
   "id": "d8c49d7f",
   "metadata": {},
   "source": [
    "# 注意：一段代码分开写要每一个运行，不可以断开"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "2fe26e83",
   "metadata": {},
   "source": [
    "## 4.for 循环 内置函数range（）\n",
    "用例1 循环迭代数字变量"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 40,
   "id": "7ce9da68",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "1\n",
      "2\n",
      "3\n"
     ]
    }
   ],
   "source": [
    "# item 循环遍历\n",
    "for i in [1,2,3]:\n",
    "    print(i) \n",
    "# i是item简称i"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 43,
   "id": "7d9fb8e9",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "21001\n",
      "21002\n",
      "21003\n"
     ]
    }
   ],
   "source": [
    "# 自动生成学号\n",
    "for i in [1,2,3]:\n",
    "    print(i+21000)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "86e3722e",
   "metadata": {},
   "outputs": [],
   "source": [
    "# 案例 ： 某学校"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "bd284a63",
   "metadata": {},
   "source": [
    "用例2 循环迭代字符串变量"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 41,
   "id": "7559a2d3",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "H\n",
      "i\n",
      "!\n"
     ]
    }
   ],
   "source": [
    "for ch in \"Hi!\":\n",
    "    print(ch)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "c36cab38",
   "metadata": {},
   "source": [
    "用例3 迭代指定的次数"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "a922ba97",
   "metadata": {},
   "source": [
    "**range** 实验"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 44,
   "id": "9351ec9c",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "0\n",
      "1\n",
      "2\n",
      "3\n",
      "4\n"
     ]
    }
   ],
   "source": [
    "# range()自动生成想要的数值，可以控制for循环的次数，一个值 ，就是从0开始几个数\n",
    "for num in range(0,5):\n",
    "    print(num)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 45,
   "id": "9f5f0140",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "range(0, 5)"
      ]
     },
     "execution_count": 45,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# range()自动生成想要的数值，可以控制for循环的次数，两个值，从小数（2）开始，"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 46,
   "id": "73d0748e",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "0\n",
      "3\n",
      "6\n",
      "9\n"
     ]
    }
   ],
   "source": [
    "# 三个值，第三个值决定step步长\n",
    "for num in range(0,10,3):\n",
    "    print(num)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "0dcbb77e",
   "metadata": {},
   "outputs": [],
   "source": [
    "# for循环遍历案例：  某学校新闻网站数据URL列队获取\n",
    "# 中大南方-招投标-https://www.nfu.edu.cn/ztb/index.htm\n",
    "中大南方_招投标 = \"https://www.nfu.edu.cn/ztb/index.htm\"\n",
    "for page in range(27):\n",
    "    print（’"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "0e19fd53",
   "metadata": {},
   "source": [
    "## 5.Random模块"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 58,
   "id": "1f9c6484",
   "metadata": {},
   "outputs": [],
   "source": [
    "import random"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 61,
   "id": "b9169da5",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0.8056693758959682"
      ]
     },
     "execution_count": 61,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# random.random方法：取（0,1）\n",
    "random.random()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 65,
   "id": "60a15c09",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "1"
      ]
     },
     "execution_count": 65,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# random.randint(a,b),随机生成a-b之间的一个数值\n",
    "random.randint(1,6)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 67,
   "id": "7c6b0389",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "4\n",
      "2\n",
      "3\n",
      "1\n",
      "2\n"
     ]
    }
   ],
   "source": [
    "# 来五组\n",
    "for i in range(5):\n",
    "    print(random.randint(1,6))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 66,
   "id": "0f65432e",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'hhhh'"
      ]
     },
     "execution_count": 66,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "random.choice([\"hhhh\",\"hhhhu\",\"jjj\"]) # 随机选择文本"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 68,
   "id": "52f14c5a",
   "metadata": {},
   "outputs": [
    {
     "ename": "NameError",
     "evalue": "name '课本p35案例' is not defined",
     "output_type": "error",
     "traceback": [
      "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m",
      "\u001b[1;31mNameError\u001b[0m                                 Traceback (most recent call last)",
      "Input \u001b[1;32mIn [68]\u001b[0m, in \u001b[0;36m<cell line: 1>\u001b[1;34m()\u001b[0m\n\u001b[1;32m----> 1\u001b[0m \u001b[43m课本p35案例\u001b[49m\n",
      "\u001b[1;31mNameError\u001b[0m: name '课本p35案例' is not defined"
     ]
    }
   ],
   "source": [
    "课本p35案例"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 69,
   "id": "129c9ac2",
   "metadata": {},
   "outputs": [],
   "source": [
    "import time"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 70,
   "id": "e5d88a17",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "hello word!\n"
     ]
    }
   ],
   "source": [
    "time.sleep(3)\n",
    "print (\"hello word!\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "33e65355",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": 74,
   "id": "bd94f777",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "28\n",
      "现在秒/时间为偶数\n",
      "31\n",
      "现在是秒/时间为奇数\n",
      "34\n",
      "现在秒/时间为偶数\n",
      "37\n",
      "现在是秒/时间为奇数\n",
      "40\n",
      "现在秒/时间为偶数\n"
     ]
    }
   ],
   "source": [
    "import datetime\n",
    "# 本项目用到了时间模块\n",
    "# print(datetime.datetime.today().microsecond)\n",
    "\n",
    "# odds 是一个变量，后面可以直接使用\n",
    "odds = [  1, 3,  5,  7,  9, 11,13,15,17,19,\n",
    "             21,23,25,27,29,31,33,35,37,39,\n",
    "             41,43,45,47,49,51,53,55,57,59]\n",
    "for i in range(5):\n",
    "    right_this_minute = datetime.datetime.today().second\n",
    "    if right_this_minute in odds:\n",
    "        print(right_this_minute)\n",
    "        print(\"现在是秒/时间为奇数\")\n",
    "    else:\n",
    "        print(right_this_minute)\n",
    "        print(\"现在秒/时间为偶数\")\n",
    "    time.sleep(3)\n",
    "# print(datetime.datetime.today().microsecond)\n",
    " \n",
    "# 注意层级关系，最上面的要在前面\n",
    "# 爬虫，爬数据，每隔5秒抓一次\n",
    "# 反爬虫\n",
    "  "
   ]
  },
  {
   "cell_type": "markdown",
   "id": "3033a3db",
   "metadata": {},
   "source": [
    "## 课本43页实践"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 86,
   "id": "cd2a27b1",
   "metadata": {},
   "outputs": [
    {
     "ename": "SyntaxError",
     "evalue": "invalid syntax (658183420.py, line 12)",
     "output_type": "error",
     "traceback": [
      "\u001b[1;36m  Input \u001b[1;32mIn [86]\u001b[1;36m\u001b[0m\n\u001b[1;33m    if new_num = 1:\u001b[0m\n\u001b[1;37m               ^\u001b[0m\n\u001b[1;31mSyntaxError\u001b[0m\u001b[1;31m:\u001b[0m invalid syntax\n"
     ]
    }
   ],
   "source": [
    "word = \"bottles\"\n",
    "\n",
    "for beer_num in range(99,0,-1):\n",
    "    print(beer_num,word,\"在啤酒墙上\")\n",
    "    print(beer_num,word,\"啤酒\")\n",
    "    print(\"拿一瓶\")\n",
    "    print(\"传递它\")\n",
    "    if beer_num == 1:\n",
    "        print(\"没有更多的啤酒了，我要自己留着\")\n",
    "    else:\n",
    "        new_num = beer_num - 1\n",
    "        if new_num = 1:\n",
    "            word = \"bottle\"\n",
    "        print(beer_num,word, \"在啤酒墙上\")\n"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "275ee282",
   "metadata": {},
   "source": [
    "## 6.额外的注释内容"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "e2d187c2",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.9.12"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
